/**
 * 设置cookie - setCookie(option)
 * @param {Object}   option                   参数
 * @param {String}   option -- key            键
 * @param {String}   option -- value          值
 * @param {Number}   option -- expireDays     过期时间
 * @param {Number}   option -- domain         域
 * @param {Number}   option -- routing        路径
 */
export const setCookie = function (cname:any, cvalue:any, exdays:any) {
    let d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    let expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires + ';path=/';
}

/**
 * 获取cookie - getCookie(key)
 * @param  {Object}   key                 键
 * @result {*}        result              返回cookie值，没有就返回空
 */
export const getCookie = function (cname: string) {
    let name = cname + "=";
    let ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); }
    }
    return "";
}

/**
 * 删除cookie - removeCookie(key)
 * @param  {Object}   key                 键
 */
export const removeCookie = function (key: string) {
    setCookie(key, '', -1)
}  